package com.barry.utils;

import java.io.File;
import java.io.InputStream;

/**
 * @ClassName FileUtil
 * @Description 文件工具类
 * @Author wangxuexing
 * @Date 2020/2/21 17:30
 * @Version 1.0
 */
public class FileUtil {

    public static InputStream getResourcesFileInputStream(String fileName) {
        return Thread.currentThread().getContextClassLoader().getResourceAsStream("" + fileName);
    }

    public static String getPath() {
        return FileUtil.class.getResource("/").getPath()+ "template" + File.separator;
    }

    public static InputStream getInputStream(String fileName) {
        return FileUtil.class.getClassLoader().getResourceAsStream("template" + File.separator+fileName);
    }

    public static File createNewFile(String pathName) {
        File file = new File(getPath() + pathName);
        if (file.exists()) {
            file.delete();
        } else {
            if (!file.getParentFile().exists()) {
                file.getParentFile().mkdirs();
            }
        }
        return file;
    }

    public static File getFile(String pathName) {
        return new File(getPath() + pathName);
    }

}
